package com.lineage.data.item_etcitem;

import com.lineage.config.ConfigOther;
import com.lineage.data.executor.ItemExecutor;
import com.lineage.data.item_etcitem.allcall.AllCall;
import com.lineage.server.datatables.MapsTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1CastleLocation;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Clan;
import com.lineage.server.model.L1Object;
import com.lineage.server.serverpackets.S_PacketBoxGree;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.World;
import com.lineage.server.world.WorldClan;
import java.util.ArrayList;
import java.util.List;

public class AllCall_clan extends AllCall {
  private int type = 0;
  
  public static ItemExecutor get() {
    return (ItemExecutor)new AllCall_clan();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    if (L1CastleLocation.checkInAllWarArea(pc.getX(), pc.getY(), pc.getMapId())) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("旗子内禁止使用"));
      return;
    } 
    if (pc.getClanid() == 0) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fY您尚未加入血盟无法使用"));
      return;
    } 
    if (ConfigOther.AllCall_clan_Crown && !pc.isCrown()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fY您的职业不是王族无法使用"));
      return;
    } 
    if (!pc.getMap().isClanPc()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("所在地图无法进行传送"));
      return;
    } 
    if (checkPcHasSkillEffect(pc).booleanValue())
      return; 
    if (this.type == 1) {
      List<L1PcInstance> players = World.get().getRecognizePlayer((L1Object)pc);
      for (L1PcInstance otherPlayer : players) {
        if (otherPlayer.getClanid() != pc.getClanid()) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage("有其他血盟成员，无法使用穿云箭"));
          pc.sendPackets((ServerBasePacket)new S_ServerMessage("请到没有人的地方使用"));
          return;
        } 
      } 
    } 
    if (this.type == 2) {
      List<L1PcInstance> players = World.get().getRecognizePlayer((L1Object)pc);
      for (L1PcInstance otherPlayer : players) {
        if (otherPlayer.getClanid() != 0 && 
          otherPlayer.getClanid() != pc.getClanid()) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage("有其他血盟成员，无法使用穿云箭"));
          pc.sendPackets((ServerBasePacket)new S_ServerMessage("请到没有人的地方使用"));
          return;
        } 
      } 
    } 
    if (pc.getInventory().checkItem(ConfigOther.Call_clan_itemid, ConfigOther.Call_clan_count)) {
      pc.getInventory().consumeItem(ConfigOther.Call_clan_itemid, ConfigOther.Call_clan_count);
      World.get().broadcastPacketToAll((ServerBasePacket)new S_SystemMessage(
            String.format(ConfigOther.clanmsg, new Object[] { pc.getClanname(), pc.getName(), MapsTable.get().getMapName(pc.getMapId()), item.getItem().getName() })));
      World.get().broadcastPacketToAll((ServerBasePacket)new S_PacketBoxGree(2, 
            String.format(ConfigOther.clanmsg, new Object[] { pc.getClanname(), pc.getName(), MapsTable.get().getMapName(pc.getMapId()), item.getItem().getName() })));
      L1Clan clan = WorldClan.get().getClan(pc.getClanname());
      L1PcInstance[] clanMembers = clan.getOnlineClanMember();
      pc.sendPackets((ServerBasePacket)new S_SkillSound(pc.getId(), 2047));
      List<L1PcInstance> pcInstanceList = new ArrayList<>();
      byte b;
      int i;
      L1PcInstance[] arrayOfL1PcInstance1;
      for (i = (arrayOfL1PcInstance1 = clanMembers).length, b = 0; b < i; ) {
        L1PcInstance clanMember1 = arrayOfL1PcInstance1[b];
        if (clanMember1.getId() != pc.getId())
          if (!checkPcHasSkillEffect(clanMember1).booleanValue()) {
            clanMember1.setcallclanal(pc.getId());
            teleport_AllCall((L1Character)clanMember1, (L1Character)pc, 2);
          }  
        b++;
      } 
    } else {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(ConfigOther.clanmsg1));
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this.type = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
  }
}
